<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-16
 * Time: 15:57
 */

namespace app\api\controller\v1;


use app\api\model\UserMoney;
use app\api\model\UserMoneyOne;
use app\api\service\money\MinMoneySer;
use app\api\service\money\MoneyOrderSer;
use app\api\service\money\UpdateUserMoneySer;
use app\api\service\Token;
use think\facade\Request;

class Money
{
    /**
     * 创建余额订单
     * return 支付number
     */
    public function placeOrder($cost_id,$money)
    {
        $moneyOrder = new MoneyOrderSer($cost_id,$money);
        return $moneyOrder->place();
    }

    /**
     * 使用余额进行支付
     */
    public function updateMoney($money,$store_id)
    {
        $minMoney = new MinMoneySer($money,$store_id);
        return $minMoney->entrance();
    }

    /**
     * 用户余额列表
     */
    public function getMoneyList()
    {
        $uid = Token::getCurrentUid();
        return UserMoney::where('user_id',$uid)->with('store')->order('id desc')->select()->toArray();
    }

    /**
     * 用户余额列表
     */
    public function getMoneyOneList()
    {
        $uid = Token::getCurrentUid();
        return UserMoneyOne::where('user_id',$uid)->order('id desc')->select()->toArray();
    }


    /**
     * 用户余额列表
     */
    public function getMoney()
    {
        $uid = Token::getCurrentUid();
        return UserMoney::where('user_id',$uid)
            ->where('type',3)->with('store')
            ->order('id desc')
            ->select()->toArray();
    }


    /**
     * 用户余额转移
     */
    public function updateUserMoney()
    {
        $post = Request::post();
        $updateUserMOney = new UpdateUserMoneySer($post);
        return $updateUserMOney->entrance();
    }
}